package com.itboye.jinpuyiyuan.utils.dialog;

import android.content.Context;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.adapter.DateAdapter;

import java.util.ArrayList;

/**
 *   挂号时间的 选择dialog
 * Created by Administrator on 2018/3/14 0014.
 */

public class RxDialogDate extends RxDialog {
    private ArrayList<String> list;
    private ListView dateList;
    private TextView titleTv;
    private Button sureBtn;
    public RxDialogDate(Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    public RxDialogDate(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
    }

    public RxDialogDate(Context context) {
        super(context);
        initView();
    }



    public RxDialogDate(Context context, float alpha, int gravity) {
        super(context, alpha, gravity);
        initView();

    }

    /**
     *
     * @param context
     * @param currentHour 挂号的开始时间
     * @param endHour     挂号的结束时间
     */

    public RxDialogDate(Context context , int currentHour, int endHour,String title,String sure){
        super(context);
        initView();
        list= new ArrayList<>();
        titleTv.setText(title);
        sureBtn.setText(sure);
        for (int i=currentHour;i<endHour;i++){
            list.add(i+":00-"+(++i)+":00");
        }
        DateAdapter mDateAdapter =new DateAdapter(context,list,dateList);
        dateList.setAdapter(mDateAdapter);
        this.setListDialogHeigh();
        sureBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RxDialogDate.this.cancel();
            }
        });

    }
    public  void setListDialogHeigh(){
        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();  //为获取屏幕宽、高
        android.view.WindowManager.LayoutParams p = getWindow().getAttributes();  //获取对话框当前的参数值
//        p.height = (int) (d.getHeight() * 0.4);   //高度设置为屏幕的0.3
        p.width = (int) (d.getWidth() * 0.6);    //宽度设置为屏幕的0.5
        getWindow().setAttributes(p);     //设置生效
    }
    private void initView() {
        View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_date, null);
        dateList= dialogView.findViewById(R.id.dateList);
        titleTv =dialogView.findViewById(R.id.titleTv);
        sureBtn = dialogView.findViewById(R.id.sureBtn);
        setContentView(dialogView);
    }
}
